using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{

    public partial class VQORDER
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                case "TST":
                default:
                    #region=========
                    dwReturn["QOKMANDANT"] = app.Mandant;
                    dwReturn["QOKORDER"] = "000000037";
                    dwReturn["QOKNEUB"] = "SYS     ";
                    dwReturn["QOKNEUD"] = "20140618";
                    dwReturn["QOKAENB"] = "SYS     ";
                    dwReturn["QOKAEND"] = "20140618";
                    dwReturn["QOKAENZL"] = "2";
                    dwReturn["QOKERLDAT"] = "0";
                    dwReturn["QOKSTATUS"] = "  ";
                    dwReturn["QOKRESULT"] = "N";
                    dwReturn["QOKMRESULT"] = "N";
                    dwReturn["QOKPNRKRS"] = "NT";
                    dwReturn["QOKPLFDNR"] = "000002";
                    dwReturn["QOKPROVOR"] = "        ";
                    dwReturn["QOKGKREGEL"] = "00000000";
                    dwReturn["QOKPRSTK"] = "0";
                    dwReturn["QOKDYNTAB"] = "TP";
                    dwReturn["QOKPRSFE"] = "1";
                    dwReturn["QOKPREINHT"] = "TP";
                    dwReturn["QOKPRODPART"] = "           ";
                    dwReturn["QOKGEBINDE"] = "          ";
                    dwReturn["QOKKUNDPART"] = "               ";
                    dwReturn["QOKVKKUNDNR"] = "00000000";
                    dwReturn["QOKLIEFNR"] = "        ";
                    dwReturn["QOKWEPARTIE"] = "  000000";
                    dwReturn["QOKARTST"] = " ";
                    dwReturn["QOKKUNDNR"] = "00000000";
                    dwReturn["QOKWERK"] = "   ";
                    dwReturn["QOKABT"] = "   ";
                    dwReturn["QOKART"] = "                    ";
                    dwReturn["QOKVAR"] = "   ";
                    dwReturn["QOKDESS"] = "          ";
                    dwReturn["QOKCOLORIT"] = "          ";
                    dwReturn["QOKFARBE"] = "          ";
                    dwReturn["QOKBESCHICH"] = "          ";
                    dwReturn["QOKZUSTAND"] = "    ";
                    dwReturn["QOKGROE"] = "       ";
                    dwReturn["QOKAUFTYP"] = " ";
                    dwReturn["QOKAUFKRS"] = "  ";
                    dwReturn["QOKAUFLFD"] = "000000";
                    dwReturn["QOKAUFPOS"] = "000";
                    dwReturn["QOKAFOLGE"] = "000";
                    dwReturn["QOKTP"] = "0000";
                    dwReturn["QOKFRBENID"] = "        ";
                    dwReturn["QOKABBENID"] = "        ";
                    dwReturn["QOKABGRD"] = "  ";
                    dwReturn["QOKRKSTKRS"] = "  ";
                    dwReturn["QOKRKST"] = "0000";
                    dwReturn["QOKVERUR"] = "               ";
                    dwReturn["QOKSKIPLOS"] = " ";
                    dwReturn["QOKRORDER"] = "000000000";
                    dwReturn["QOKVKZ"] = " ";
                    dwReturn["QOKPKUNDNR"] = "00000000";
                    dwReturn["QOKPADRSL"] = "        ";
                    dwReturn["QOKVKAUFTYP"] = " ";
                    dwReturn["QOKVKAUFKRS"] = "  ";
                    dwReturn["QOKVKAUFLFD"] = "000000";
                    dwReturn["QOKVKAUFPOS"] = "000";
                    dwReturn["QOKARCHBEL"] = "0";
                    dwReturn["QOKARCHBELQ"] = "0";
                    dwReturn["QOKAPOS"] = "0000";
                    dwReturn["QOKAFOLGELC"] = "000";
                    dwReturn["QOKLKSTKRS"] = "  ";
                    dwReturn["QOKLKST"] = "0000";
                    dwReturn["QOKMNRKRS"] = "  ";
                    dwReturn["QOKMLFDNR"] = "0000";
                    dwReturn["QOKMPOS"] = "00";
                    dwReturn["QOKAGANG"] = "               ";
                    dwReturn["QOKNEUZEIT"] = "0";
                    dwReturn["QOKMAINPROG"] = "        ";
                    dwReturn["QOKPRODDAT"] = "0";
                    dwReturn["QOKPKSTKRS"] = "  ";
                    dwReturn["QOKPKST"] = "0000";
                    dwReturn["QOKWOCHE"] = "  ";
                    dwReturn["QOKSCHICHT"] = "0";
                    dwReturn["QOKSADATUM"] = "0";
                    dwReturn["QOKSAZEIT"] = "0";
                    dwReturn["QOKADDTEST"] = " ";
                    dwReturn["QOKPKUNDUR"] = "A";
                    dwReturn["QOKINMANDANT"] = "  ";
                    dwReturn["QOKAUSMANDANT"] = "  ";
                    dwReturn["QOKVERDICHTET"] = " ";
                    dwReturn["QOKABGDATUM"] = "0";
                    dwReturn["QOKABGZEIT"] = "0";
                    dwReturn["QOKABGBENID"] = "        ";
                    dwReturn["QOKTYPE"] = "NO ";
                    dwReturn["QOKFILLER4"] = "                            ";
                    #endregion
                    break;
            }
        }
        public void InsertQORDER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QORDER ( QOKMANDANT,QOKORDER,QOKNEUB,QOKNEUD,QOKAENB,QOKAEND,QOKAENZL,QOKERLDAT,QOKSTATUS,QOKRESULT,QOKMRESULT,QOKPNRKRS,QOKPLFDNR,QOKPROVOR,QOKGKREGEL,QOKPRSTK,QOKDYNTAB,QOKPRSFE,QOKPREINHT,QOKPRODPART,QOKGEBINDE,QOKKUNDPART,QOKVKKUNDNR,QOKLIEFNR,QOKWEPARTIE,QOKARTST,QOKKUNDNR,QOKWERK,QOKABT,QOKART,QOKVAR,QOKDESS,QOKCOLORIT,QOKFARBE,QOKBESCHICH,QOKZUSTAND,QOKGROE,QOKAUFTYP,QOKAUFKRS,QOKAUFLFD,QOKAUFPOS,QOKAFOLGE,QOKTP,QOKFRBENID,QOKABBENID,QOKABGRD,QOKRKSTKRS,QOKRKST,QOKVERUR,QOKSKIPLOS,QOKRORDER,QOKVKZ,QOKPKUNDNR,QOKPADRSL,QOKVKAUFTYP,QOKVKAUFKRS,QOKVKAUFLFD,QOKVKAUFPOS,QOKARCHBEL,QOKARCHBELQ,QOKAPOS,QOKAFOLGELC,QOKLKSTKRS,QOKLKST,QOKMNRKRS,QOKMLFDNR,QOKMPOS,QOKAGANG,QOKNEUZEIT,QOKMAINPROG,QOKPRODDAT,QOKPKSTKRS,QOKPKST,QOKWOCHE,QOKSCHICHT,QOKSADATUM,QOKSAZEIT,QOKADDTEST,QOKPKUNDUR,QOKINMANDANT,QOKAUSMANDANT,QOKVERDICHTET,QOKABGDATUM,QOKABGZEIT,QOKABGBENID,QOKTYPE,QOKFILLER4)"
                    + " VALUES (:QOKMANDANT:,:QOKORDER:,:QOKNEUB:,:QOKNEUD:,:QOKAENB:,:QOKAEND:,:QOKAENZL:,:QOKERLDAT:,:QOKSTATUS:,:QOKRESULT:,:QOKMRESULT:,:QOKPNRKRS:,:QOKPLFDNR:,:QOKPROVOR:,:QOKGKREGEL:,:QOKPRSTK:,:QOKDYNTAB:,:QOKPRSFE:,:QOKPREINHT:,:QOKPRODPART:,:QOKGEBINDE:,:QOKKUNDPART:,:QOKVKKUNDNR:,:QOKLIEFNR:,:QOKWEPARTIE:,:QOKARTST:,:QOKKUNDNR:,:QOKWERK:,:QOKABT:,:QOKART:,:QOKVAR:,:QOKDESS:,:QOKCOLORIT:,:QOKFARBE:,:QOKBESCHICH:,:QOKZUSTAND:,:QOKGROE:,:QOKAUFTYP:,:QOKAUFKRS:,:QOKAUFLFD:,:QOKAUFPOS:,:QOKAFOLGE:,:QOKTP:,:QOKFRBENID:,:QOKABBENID:,:QOKABGRD:,:QOKRKSTKRS:,:QOKRKST:,:QOKVERUR:,:QOKSKIPLOS:,:QOKRORDER:,:QOKVKZ:,:QOKPKUNDNR:,:QOKPADRSL:,:QOKVKAUFTYP:,:QOKVKAUFKRS:,:QOKVKAUFLFD:,:QOKVKAUFPOS:,:QOKARCHBEL:,:QOKARCHBELQ:,:QOKAPOS:,:QOKAFOLGELC:,:QOKLKSTKRS:,:QOKLKST:,:QOKMNRKRS:,:QOKMLFDNR:,:QOKMPOS:,:QOKAGANG:,:QOKNEUZEIT:,:QOKMAINPROG:,:QOKPRODDAT:,:QOKPKSTKRS:,:QOKPKST:,:QOKWOCHE:,:QOKSCHICHT:,:QOKSADATUM:,:QOKSAZEIT:,:QOKADDTEST:,:QOKPKUNDUR:,:QOKINMANDANT:,:QOKAUSMANDANT:,:QOKVERDICHTET:,:QOKABGDATUM:,:QOKABGZEIT:,:QOKABGBENID:,:QOKTYPE:,:QOKFILLER4:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    break;
                default:
                case "JLT":
                    or1.CommandText = "INSERT INTO QORDER ( QOKMANDANT,QOKORDER,QOKNEUB,QOKNEUD,QOKAENB,QOKAEND,QOKAENZL,QOKERLDAT,QOKSTATUS,QOKRESULT,QOKMRESULT,QOKPNRKRS,QOKPLFDNR,QOKPROVOR,QOKGKREGEL,QOKPRSTK,QOKDYNTAB,QOKPRSFE,QOKPREINHT,QOKPRODPART,QOKGEBINDE,QOKKUNDPART,QOKVKKUNDNR,QOKLIEFNR,QOKWEPARTIE,QOKARTST,QOKKUNDNR,QOKWERK,QOKABT,QOKART,QOKVAR,QOKDESS,QOKCOLORIT,QOKFARBE,QOKBESCHICH,QOKZUSTAND,QOKGROE,QOKAUFTYP,QOKAUFKRS,QOKAUFLFD,QOKAUFPOS,QOKAFOLGE,QOKTP,QOKFRBENID,QOKABBENID,QOKABGRD,QOKRKSTKRS,QOKRKST,QOKVERUR,QOKSKIPLOS,QOKRORDER,QOKVKZ,QOKPKUNDNR,QOKPADRSL,QOKVKAUFTYP,QOKVKAUFKRS,QOKVKAUFLFD,QOKVKAUFPOS,QOKARCHBEL,QOKARCHBELQ,QOKAPOS,QOKAFOLGELC,QOKLKSTKRS,QOKLKST,QOKMNRKRS,QOKMLFDNR,QOKMPOS,QOKAGANG,QOKNEUZEIT,QOKMAINPROG,QOKPRODDAT,QOKPKSTKRS,QOKPKST,QOKWOCHE,QOKSCHICHT,QOKSADATUM,QOKSAZEIT,QOKADDTEST,QOKPKUNDUR,QOKINMANDANT,QOKAUSMANDANT,QOKVERDICHTET,QOKABGDATUM,QOKABGZEIT,QOKABGBENID,QOKTYPE,QOKFILLER4)"
                    + " VALUES (:QOKMANDANT:,:QOKORDER:,:QOKNEUB:,:QOKNEUD:,:QOKAENB:,:QOKAEND:,:QOKAENZL:,:QOKERLDAT:,:QOKSTATUS:,:QOKRESULT:,:QOKMRESULT:,:QOKPNRKRS:,:QOKPLFDNR:,:QOKPROVOR:,:QOKGKREGEL:,:QOKPRSTK:,:QOKDYNTAB:,:QOKPRSFE:,:QOKPREINHT:,:QOKPRODPART:,:QOKGEBINDE:,:QOKKUNDPART:,:QOKVKKUNDNR:,:QOKLIEFNR:,:QOKWEPARTIE:,:QOKARTST:,:QOKKUNDNR:,:QOKWERK:,:QOKABT:,:QOKART:,:QOKVAR:,:QOKDESS:,:QOKCOLORIT:,:QOKFARBE:,:QOKBESCHICH:,:QOKZUSTAND:,:QOKGROE:,:QOKAUFTYP:,:QOKAUFKRS:,:QOKAUFLFD:,:QOKAUFPOS:,:QOKAFOLGE:,:QOKTP:,:QOKFRBENID:,:QOKABBENID:,:QOKABGRD:,:QOKRKSTKRS:,:QOKRKST:,:QOKVERUR:,:QOKSKIPLOS:,:QOKRORDER:,:QOKVKZ:,:QOKPKUNDNR:,:QOKPADRSL:,:QOKVKAUFTYP:,:QOKVKAUFKRS:,:QOKVKAUFLFD:,:QOKVKAUFPOS:,:QOKARCHBEL:,:QOKARCHBELQ:,:QOKAPOS:,:QOKAFOLGELC:,:QOKLKSTKRS:,:QOKLKST:,:QOKMNRKRS:,:QOKMLFDNR:,:QOKMPOS:,:QOKAGANG:,:QOKNEUZEIT:,:QOKMAINPROG:,:QOKPRODDAT:,:QOKPKSTKRS:,:QOKPKST:,:QOKWOCHE:,:QOKSCHICHT:,:QOKSADATUM:,:QOKSAZEIT:,:QOKADDTEST:,:QOKPKUNDUR:,:QOKINMANDANT:,:QOKAUSMANDANT:,:QOKVERDICHTET:,:QOKABGDATUM:,:QOKABGZEIT:,:QOKABGBENID:,:QOKTYPE:,:QOKFILLER4:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryQORDER(DataRow dwData, int option = 1)
        {
            DataSet Result;
            or1 = OracleDB.CreateCommand();
            string qm = "";
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QORDER WHERE  ROWNUM<2 ";
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM QORDER WHERE  QOKMANDANT=:QOKMANDANT: AND QOKWEPARTIE=:QOKWEPARTIE: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM QORDER WHERE  QOKMANDANT=:QOKMANDANT: AND QOKORDER=:QOKORDER: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 4:
                    or1.CommandText = "SELECT DISTINCT " + dwData["QOKFILLER4"].ToString() + ",Q.*"
                    + " FROM QORDER Q  JOIN QOSTEP ON  QOKMANDANT=QOEMANDANT AND QOKORDER=QOEORDER "
                    + " WHERE QOKMANDANT=:QOKMANDANT: AND QOKAUFTYP=:QOKAUFTYP: AND QOKAUFKRS=:QOKAUFKRS: AND QOKAUFLFD=:QOKAUFLFD: AND QOKAUFPOS=:QOKAUFPOS:"
                    + " AND QOKORDER LIKE '%" + dwData["QOKORDER"].ToString().Trim() + "%'";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 5:
                    qm = VQPMERKM.Instance.BXQT();
                    or1.CommandText = "SELECT DISTINCT " + qm + "  MAX(Q.QOKORDER) AS QOKORDER,Q.QOKPRODPART AS GPPARTIE,MAX(Q.QOKART) AS ABPART,MAX(Q.QOKVAR) AS ABPVAR,MAX(Q.QOKFARBE) AS ABPFARBE, "
+ " MAX(Q.QOKNEUD) AS QOKNEUD,MAX(G.GSFACH) AS GSFACH,MAX(TRIM(SUBSTR(VKPKDBEZ, 21, 10))) AS VKPKDBEZ "
+ " FROM QORDER Q,GSDAT G,VKPOS K, "
+ " (SELECT DISTINCT GPAMANDANT,GPASPPART,GPAAUFKRS,GPAAUFLFD,GPAAUFPOS,GPAART,GPAVAR,GPAFARBE FROM GPACK X WHERE X.GPALIEFSCH =:VVLIEFSCH:  "
+ " UNION ALL "
+ " SELECT DISTINCT VVTMANDANT,P.GPSPPART,V.VVTAUFKRS,V.VVTAUFLFD,V.VVTAUFPOS,P.GPGART,P.GPGVAR,P.GPGFARBE "
+ " FROM VVTLIEF V,ZUTEI U,GPDAT P WHERE V.VVTLIEFSCH = :VVLIEFSCH:  AND V.VVTMANDANT = U.ZUMANDANT AND V.VVTAUFKRS = U.ZUAUFKRS  "
+ " AND V.VVTAUFLFD = U.ZUAUFLFD AND V.VVTAUFPOS = U.ZUAUFPOS AND U.ZUMANDANT = P.GPMANDANT AND U.ZUPARTIE = P.GPPARTIE AND U.ZUPARTIEKZ = P.GPPARTIEKZ ) Z "
+ " WHERE G.GSMANDANT = Q.QOKMANDANT AND Q.QOKART = G.GSART and Q.QOKVAR = G.GSVAR and K.VKPSA = '  ' "
+ " AND VKPAUFKRS = Z.GPAAUFKRS AND VKPAUFLFD = Z.GPAAUFLFD AND VKPAUFPOS = Z.GPAAUFPOS AND Z.GPAMANDANT = Q.QOKMANDANT "
+ " AND Z.GPAART = Q.QOKART AND Z.GPAFARBE = Q.QOKFARBE AND Z.GPAVAR = Q.QOKVAR AND TRIM(Z.GPASPPART) = TRIM(Q.QOKPRODPART) "
+ " GROUP BY QOKPRODPART order by QOKORDER ";

                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 6:
                    qm = VQPMERKM.Instance.TTLQT();
                    or1.CommandText = "SELECT DISTINCT " + qm + " Q.QOKORDER AS QOKORDER,Q.QOKPRODPART AS GPPARTIE,Q.QOKART AS ABPART,Q.QOKVAR AS ABPVAR,Q.QOKFARBE AS ABPFARBE, "
 + " Q.QOKNEUD AS QOKNEUD,G.GSFACH AS GSFACH,TRIM(SUBSTR(VKPKDBEZ, 21, 10)) AS VKPKDBEZ "
 + " FROM QORDER Q,GSDAT G,VKPOS K, "
 + " (SELECT DISTINCT GPAMANDANT,GPASPPART,GPAAUFKRS,GPAAUFLFD,GPAAUFPOS,GPAART,GPAVAR,GPAFARBE FROM GPACK X WHERE X.GPALIEFSCH =:VVLIEFSCH:  "
 + " UNION ALL "
 + " SELECT DISTINCT VVTMANDANT,P.GPSPPART,V.VVTAUFKRS,V.VVTAUFLFD,V.VVTAUFPOS,P.GPGART,P.GPGVAR,P.GPGFARBE "
 + " FROM VVTLIEF V,ZUTEI U,GPDAT P WHERE V.VVTLIEFSCH = :VVLIEFSCH: AND V.VVTMANDANT = U.ZUMANDANT AND V.VVTAUFKRS = U.ZUAUFKRS  "
 + " AND V.VVTAUFLFD = U.ZUAUFLFD AND V.VVTAUFPOS = U.ZUAUFPOS AND U.ZUMANDANT = P.GPMANDANT AND U.ZUPARTIE = P.GPPARTIE AND U.ZUPARTIEKZ = P.GPPARTIEKZ ) Z "
 + " WHERE G.GSMANDANT = Q.QOKMANDANT AND Q.QOKART = G.GSART and Q.QOKVAR = G.GSVAR and K.VKPSA = '  ' "
 + " AND VKPAUFKRS = Z.GPAAUFKRS AND VKPAUFLFD = Z.GPAAUFLFD AND VKPAUFPOS = Z.GPAAUFPOS AND Z.GPAMANDANT = Q.QOKMANDANT "
 + " AND Z.GPAART = Q.QOKART AND Z.GPAFARBE = Q.QOKFARBE AND Z.GPAVAR = Q.QOKVAR AND TRIM(Z.GPASPPART) = TRIM(Q.QOKPRODPART) "
 + "  order by QOKORDER ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                //case 5:
                //    qm = VQPMERKM.Instance.BXQT();
                //    or1.CommandText = "SELECT  DISTINCT " + qm + " MAX(Q.QOKORDER) AS QOKORDER,MAX(Q.QOKPRODPART) AS GPPARTIE,MAX(Q.QOKART) AS ABPART,MAX(Q.QOKVAR) AS ABPVAR,MAX(Q.QOKFARBE) AS ABPFARBE,MAX(Q.QOKNEUD) AS QOKNEUD ,MAX(G.GSFACH) AS GSFACH,MAX(TRIM (SUBSTR (VKPKDBEZ,21,10))) AS VKPKDBEZ"
                //    + " FROM QORDER Q,GSDAT G,VKPOS K ,(SELECT DISTINCT GPAMANDANT,QOKORDER,GPASPPART,GPAAUFKRS,GPAAUFLFD,GPAAUFPOS,GPAART,GPAVAR,GPAFARBE  FROM GPACK X,QORDER T  WHERE X.GPALIEFSCH = :VVLIEFSCH: AND X.GPAMANDANT = T.QOKMANDANT AND X.GPAART= T.QOKART AND  X.GPAFARBE=T.QOKFARBE  AND X.GPAVAR =T.QOKVAR AND TRIM(X.GPASPPART) = TRIM(T.QOKPRODPART))Z"
                //    + " WHERE  G.GSMANDANT = Q.QOKMANDANT AND Q.QOKART = G.GSART and Q.QOKVAR=G.GSVAR and K.VKPSA='  ' AND VKPAUFKRS=Z.GPAAUFKRS  AND VKPAUFLFD=Z.GPAAUFLFD  AND VKPAUFPOS=Z.GPAAUFPOS  AND Q.QOKORDER =Z.QOKORDER"
                //    + " GROUP BY QOKPRODPART"
                //    + " order by QOKORDER";
                //    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                //    break;
                //case 6:
                //    qm = VQPMERKM.Instance.TTLQT();
                //    or1.CommandText = "SELECT  DISTINCT " + qm + "  Q.QOKORDER,Q.QOKPRODPART AS GPPARTIE,Q.QOKART AS ABPART,Q.QOKVAR AS ABPVAR,Q.QOKFARBE AS ABPFARBE,Q.QOKNEUD,G.GSFACH,TRIM (SUBSTR (VKPKDBEZ,21,10)) AS VKPKDBEZ"
                //    + " FROM QORDER Q,GSDAT G,VKPOS K ,(SELECT DISTINCT GPAMANDANT, QOKORDER,GPASPPART, GPAAUFKRS,GPAAUFLFD,GPAAUFPOS,GPAART, GPAVAR,GPAFARBE FROM GPACK X, QORDER T WHERE X.GPALIEFSCH =:VVLIEFSCH:"
                //    + " AND X.GPAMANDANT = T.QOKMANDANT AND X.GPAART = T.QOKART AND X.GPAFARBE = T.QOKFARBE AND X.GPAVAR = T.QOKVAR AND TRIM(X.GPASPPART) = TRIM(T.QOKPRODPART))Z"
                //    + " WHERE G.GSMANDANT = Q.QOKMANDANT AND Q.QOKART = G.GSART and Q.QOKVAR = G.GSVAR and K.VKPSA = '  '  AND VKPAUFKRS = Z.GPAAUFKRS"
                //    + " AND VKPAUFLFD = Z.GPAAUFLFD AND VKPAUFPOS = Z.GPAAUFPOS AND Q.QOKORDER = Z.QOKORDER" 
                //    + " order by QOKORDER";
                //    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                //    break;

                case 7:
                    qm = VQPMERKM.Instance.BXQT();
                    or1.CommandText = "SELECT DISTINCT " + qm + "  MAX(Q.QOKORDER) AS QOKORDER,Q.QOKPRODPART AS GPPARTIE,MAX(Q.QOKART) AS ABPART,MAX(Q.QOKVAR) AS ABPVAR,MAX(Q.QOKFARBE) AS ABPFARBE, "
+ " MAX(Q.QOKNEUD) AS QOKNEUD,MAX(G.GSFACH) AS GSFACH,MAX(TRIM(SUBSTR(VKPKDBEZ, 21, 10))) AS TYP,Z.GPALIEFSCH,(select TRIM(KDKNAME) from KDSTAMM WHERE KDKUNDNR = K.VKPKUNDNR) AS KDNAME "
+ " FROM QORDER Q,GSDAT G,VKPOS K, "
+ " (SELECT DISTINCT GPAMANDANT,GPASPPART,GPAAUFKRS,GPAAUFLFD,GPAAUFPOS,GPAART,GPAVAR,GPAFARBE,GPALIEFSCH FROM GPACK X WHERE X.GPALIEFSCH =:VVLIEFSCH:  "
+ " UNION ALL "
+ " SELECT DISTINCT VVTMANDANT,P.GPSPPART,V.VVTAUFKRS,V.VVTAUFLFD,V.VVTAUFPOS,P.GPGART,P.GPGVAR,P.GPGFARBE,V.VVTLIEFSCH AS GPALIEFSCH "
+ " FROM VVTLIEF V,ZUTEI U,GPDAT P WHERE V.VVTLIEFSCH = :VVLIEFSCH:  AND V.VVTMANDANT = U.ZUMANDANT AND V.VVTAUFKRS = U.ZUAUFKRS  "
+ " AND V.VVTAUFLFD = U.ZUAUFLFD AND V.VVTAUFPOS = U.ZUAUFPOS AND U.ZUMANDANT = P.GPMANDANT AND U.ZUPARTIE = P.GPPARTIE AND U.ZUPARTIEKZ = P.GPPARTIEKZ ) Z "
+ " WHERE G.GSMANDANT = Q.QOKMANDANT AND Q.QOKART = G.GSART and Q.QOKVAR = G.GSVAR and K.VKPSA = '  ' "
+ " AND VKPAUFKRS = Z.GPAAUFKRS AND VKPAUFLFD = Z.GPAAUFLFD AND VKPAUFPOS = Z.GPAAUFPOS AND Z.GPAMANDANT = Q.QOKMANDANT "
+ " AND Z.GPAART = Q.QOKART AND Z.GPAFARBE = Q.QOKFARBE AND Z.GPAVAR = Q.QOKVAR AND TRIM(Z.GPASPPART) = TRIM(Q.QOKPRODPART) "
+ " GROUP BY QOKPRODPART,GPALIEFSCH,VKPKUNDNR order by QOKORDER ";

                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;

            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QORDER";
            return Result;
        }
        public void DeleteQORDER(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QORDER   WHERE  QOKMANDANT=:QOKMANDANT: AND QOKORDER=:QOKORDER:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateQORDER(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0://JLT
                    or1.CommandText = "UPDATE QORDER SET QOKMANDANT=:QOKMANDANT:,QOKORDER=:QOKORDER:,QOKNEUB=:QOKNEUB:,QOKNEUD=:QOKNEUD:,QOKAENB=:QOKAENB:,QOKAEND=:QOKAEND:,QOKAENZL=:QOKAENZL:,QOKERLDAT=:QOKERLDAT:,QOKSTATUS=:QOKSTATUS:,QOKRESULT=:QOKRESULT:,QOKMRESULT=:QOKMRESULT:,QOKPNRKRS=:QOKPNRKRS:,QOKPLFDNR=:QOKPLFDNR:,QOKPROVOR=:QOKPROVOR:,QOKGKREGEL=:QOKGKREGEL:,QOKPRSTK=:QOKPRSTK:,QOKDYNTAB=:QOKDYNTAB:,QOKPRSFE=:QOKPRSFE:,QOKPREINHT=:QOKPREINHT:,QOKPRODPART=:QOKPRODPART:,QOKGEBINDE=:QOKGEBINDE:,QOKKUNDPART=:QOKKUNDPART:,QOKVKKUNDNR=:QOKVKKUNDNR:,QOKLIEFNR=:QOKLIEFNR:,QOKWEPARTIE=:QOKWEPARTIE:,QOKARTST=:QOKARTST:,QOKKUNDNR=:QOKKUNDNR:,QOKWERK=:QOKWERK:,QOKABT=:QOKABT:,QOKART=:QOKART:,QOKVAR=:QOKVAR:,QOKDESS=:QOKDESS:,QOKCOLORIT=:QOKCOLORIT:,QOKFARBE=:QOKFARBE:,QOKBESCHICH=:QOKBESCHICH:,QOKZUSTAND=:QOKZUSTAND:,QOKGROE=:QOKGROE:,QOKAUFTYP=:QOKAUFTYP:,QOKAUFKRS=:QOKAUFKRS:,QOKAUFLFD=:QOKAUFLFD:,QOKAUFPOS=:QOKAUFPOS:,QOKAFOLGE=:QOKAFOLGE:,QOKTP=:QOKTP:,QOKFRBENID=:QOKFRBENID:,QOKABBENID=:QOKABBENID:,QOKABGRD=:QOKABGRD:,QOKRKSTKRS=:QOKRKSTKRS:,QOKRKST=:QOKRKST:,QOKVERUR=:QOKVERUR:,QOKSKIPLOS=:QOKSKIPLOS:,QOKRORDER=:QOKRORDER:,QOKVKZ=:QOKVKZ:,QOKPKUNDNR=:QOKPKUNDNR:,QOKPADRSL=:QOKPADRSL:,QOKVKAUFTYP=:QOKVKAUFTYP:,QOKVKAUFKRS=:QOKVKAUFKRS:,QOKVKAUFLFD=:QOKVKAUFLFD:,QOKVKAUFPOS=:QOKVKAUFPOS:,QOKARCHBEL=:QOKARCHBEL:,QOKARCHBELQ=:QOKARCHBELQ:,QOKAPOS=:QOKAPOS:,QOKAFOLGELC=:QOKAFOLGELC:,QOKLKSTKRS=:QOKLKSTKRS:,QOKLKST=:QOKLKST:,QOKMNRKRS=:QOKMNRKRS:,QOKMLFDNR=:QOKMLFDNR:,QOKMPOS=:QOKMPOS:,QOKAGANG=:QOKAGANG:,QOKNEUZEIT=:QOKNEUZEIT:,QOKMAINPROG=:QOKMAINPROG:,QOKPRODDAT=:QOKPRODDAT:,QOKPKSTKRS=:QOKPKSTKRS:,QOKPKST=:QOKPKST:,QOKWOCHE=:QOKWOCHE:,QOKSCHICHT=:QOKSCHICHT:,QOKSADATUM=:QOKSADATUM:,QOKSAZEIT=:QOKSAZEIT:,QOKADDTEST=:QOKADDTEST:,QOKPKUNDUR=:QOKPKUNDUR:,QOKINMANDANT=:QOKINMANDANT:,QOKAUSMANDANT=:QOKAUSMANDANT:,QOKVERDICHTET=:QOKVERDICHTET:,QOKABGDATUM=:QOKABGDATUM:,QOKABGZEIT=:QOKABGZEIT:,QOKABGBENID=:QOKABGBENID:,QOKTYPE=:QOKTYPE:,QOKFILLER4=:QOKFILLER4:"
                        + " WHERE  QOKMANDANT=:QOKMANDANT: AND QOKORDER=:QOKORDER: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
